"""
Assistant API 是百炼应用的开发工具，旨在帮助您快速、方便地构建 AI 对话助手。
本文详细阐述了 Assistant API 中 Assistant 类的各项功能，涵盖了智能体的创建、列举、检索、更新以及删除等操作。
"""
# 创建智能体
from dashscope import Assistants
import os

assistant = Assistants.create(
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        model='qwen-max',
        name='smart helper',
        description='A tool helper.',
        instructions='You are a helpful assistant. When asked a question, use tools wherever possible.',
        tools=[{
            'type': 'search'
        }, {
            'type': 'function',
            'function': {
                'name': 'big_add',
                'description': 'Add to number',
                'parameters': {
                    'type': 'object',
                    'properties': {
                        'left': {
                            'type': 'integer',
                            'description': 'The left operator'
                        },
                        'right': {
                            'type': 'integer',
                            'description': 'The right operator.'
                        }
                    },
                    'required': ['left', 'right']
                }
            }
        }],
)
print(assistant)
assistant_id = assistant.id
# 列出智能体
assistants = Assistants.list(limit=1,
                             order='desc',
                             after='',
                             before='')
print(assistants)
# 检索智能体
assistant = Assistants.retrieve(assistant_id)
print(assistant)
# 更新智能体
assistant = Assistants.update(assistant_id, model='qwen-plus')
print(assistant)
#删除智能体
deleteResp = Assistants.delete(assistant_id)
print(deleteResp)